﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace Camping_Project.Forms
{
    public partial class FormModifInfosClient : Form
    {
        private Client cli;

        public FormModifInfosClient(Client clientASupprimer)
        {
            InitializeComponent();
            cli = clientASupprimer;
        }

        private void FormModifInfosClient_Load(object sender, EventArgs e)
        {
            loadInfos(cli);
        }


        private void loadInfos(Client client)
        {
            tbNom.Text = client.Nom.Trim();
            tbPrenom.Text = client.Prenom.Trim();
            tbDateNaissance.Text = client.DateNaissance.ToString().Trim();
            tbAdresse.Text = client.Adresse.Trim();
            tbVille.Text = client.Ville.Trim();
            tbCodePostal.Text = client.CodePostal.Trim();
            tbPays.Text = client.Pays.Trim();
            tbEMail.Text = client.Email.Trim();
            tbTelephone.Text = client.Telephone.Trim();
        }


        private void updateInfos()
        {
            Camping_BDD bdd = new Camping_BDD();
            var qCli = (from c in bdd.Client
                          where c.IDClient == cli.IDClient
                          select c).Single();


            qCli.Nom = tbNom.Text;
            qCli.Prenom = tbPrenom.Text;
            qCli.DateNaissance = DateTime.Parse(tbDateNaissance.Text);
            qCli.Adresse = tbAdresse.Text;
            qCli.Ville = tbVille.Text;
            qCli.CodePostal = tbCodePostal.Text;
            qCli.Pays = tbPays.Text;
            qCli.Email = tbEMail.Text;
            qCli.Telephone = tbTelephone.Text;
            bdd.SaveChanges();

            MessageBox.Show("Le client " + tbNom.Text + " " + tbPrenom.Text + " a bien été modifié.", "Succes de l'operation", MessageBoxButtons.OK, MessageBoxIcon.Information);

        }

        private void button1_Click(object sender, EventArgs e)
        {
            updateInfos();
        }

    }
}
